package com.fulihui.information.biz.content.impl;

import com.fulihui.information.biz.content.CategoryBizManager;
import com.fulihui.information.core.db.CategoryGroupDB;
import com.fulihui.information.core.repository.CategoryRepository;
import com.fulihui.information.dto.CategoryDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author Willard.Hu on 2017/1/25 0025.
 */
@Component
public class CategoryBizManagerImpl implements CategoryBizManager {
    @Autowired
    private CategoryRepository categoryRepository;
    @Autowired
    @Qualifier("redisCategoryGroupDB")
    private CategoryGroupDB    categoryGroupDB;

    @Override
    public List<CategoryDTO> queryGroup(String productCode, String parentCode) {
        List<CategoryDTO> list = categoryGroupDB.queryGroup(parentCode, productCode);
        if (CollectionUtils.isEmpty(list)) {
            list = categoryRepository.queryGroup(productCode,
                    parentCode);
            categoryGroupDB.save(list, parentCode, productCode);
        }
        return list;
    }

    @Override
    public List<CategoryDTO> queryGroupRT(String productCode, String parentCode) {
        return categoryRepository.queryGroup(productCode,
                parentCode);
    }
}
